package com.tfswue.jqr.config;


import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

    /**
     * 配置全局 OpenAPI 信息，包括安全认证和 API 元数据
     */
    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .components(new Components()
                        .addSecuritySchemes("bearerAuth", new SecurityScheme()
                                .type(SecurityScheme.Type.HTTP)
                                .scheme("bearer")
                                .bearerFormat("JWT")))
                .info(new Info()
                        .title("图书管理系统 API 文档")
                        .description("整合 book-service 和 borrow-service 的接口文档")
                        .version("1.0.0")
                        .contact(new Contact().name("API 团队").email("api@example.com")))
                .addSecurityItem(new SecurityRequirement().addList("bearerAuth"));
    }

    /**
     * 配置 book-service 接口分组
     */
    @Bean
    public GroupedOpenApi bookServiceApi() {
        return GroupedOpenApi.builder()
                .group("book-service")
                .pathsToMatch("/book/**")
                .build();
    }

    /**
     * 配置 borrow-service 接口分组
     */
    @Bean
    public GroupedOpenApi borrowServiceApi() {
        return GroupedOpenApi.builder()
                .group("borrow-service")
                .pathsToMatch("/borrow/**")
                .build();
    }
}